package com.hongxun.design.projectutil;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.alibaba.fastjson.JSON;
import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.bean.BitTypeTabItemBean;
import com.hongxun.design.bean.CodeSetVersionBean;
import com.hongxun.design.bean.Exploration;
import com.hongxun.design.bean.ProjectItemBean;
import com.hongxun.design.bean.SearchProjectBean;
import com.hongxun.design.bean.photopassbean.SystemTypeBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.mytools.ShardPreferencesTool;
import com.hongxun.design.service.CacheDialog;
import com.hongxun.design.utils.DataUtil;
import com.hongxun.design.utils.fastjson.FastJsonUtil;
import com.hongxun.design.utils.fileutil.GetFileUtil;
import com.hongxun.design.utils.fileutil.SetFileUtil;
import com.hongxun.design.utils.httputil.HttpStringCodeTableUtil;
import com.hongxun.design.utils.httputil.HttpStringUtil;
import com.hongxun.design.utils.projectdatautil.DataFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zerdoor_pc on 2016/7/17.
 */
public class ProjectCache {
    Context context;
    Handler searchAllProjectHandler, projectListHandler, pointSumHandler, baseHandler, poleSumHandler, userPointHandler, explorSumHandler, sectionCorssHandler,
            materialSumHandler, explorationHandler, expPhotoList, beforeExpHandler, channelListHandler, channelAListHandler, envInfoHandler;
    final int httpcode = HttpStringUtil.SUCCESSED2;
    int projectNum = 0, projectsize = 0, TransformerNum = 0, Transformersize = 0;

    public ProjectCache(Context context) {
        this.context = context;
        CacheDialog.getInstence().getHandler().sendEmptyMessage(0);
        MyApp.handler.sendEmptyMessage(8);
        getProjectList(MString.ProjectStageListFile);//缓存项目列表文件
        getProjectMap(MString.ProjectListFile);//缓存项目地图
        getPersonnel(); //缓存人员信息
        //getCodeset();//缓存典设

    }
/*********************************************数据请求**************************************************/
    /**
     * 项目列表数据请求*
     */
    void getProjectList(String... save) {
        addProjectListHandler();//加载项目列表数据监听
        MyApp.HTTP.getProjectList(projectListHandler, httpcode, "", 0, 1000, save);
    }

    /**
     * 项目地图数据请求*
     */
    void getProjectMap(String... save) {
        addSearchAllProjectHandler();
        MyApp.HTTP.SearchAllProject(searchAllProjectHandler, httpcode, "", save);
    }

    /**
     * 缓存人员信息请求
     **/
    private void getPersonnel() {
        getPersonnelList("11");
        getPersonnelList("12");
        getPersonnelList("13");
        getPersonnelList("14");
    }

    private void getPersonnelList(String userType) {
        MyApp.HTTP.getPersonnelList(inItPersonnelHander(userType), HttpStringUtil.SUCCESSED2, userType, "");
    }


    /**
     * 典设缓存
     **/
    private void getCodeset() {
        List<SystemTypeBean> beans = FastJsonUtil.JsonToData_Code(HttpStringCodeTableUtil.codesetType);//典设版本类型
        List<BitTypeTabItemBean> beanList = DataUtil.getBitTypeData(1);
        beanList.add(new BitTypeTabItemBean("", "", R.mipmap.dwddahuodian, null, Constant.LOCALPOINT));
        for (SystemTypeBean s : beans) {//遍历类型
            String code = ShardPreferencesTool.getshare(context, MString.codeset_type + s.getTypecode(), "");
            if (code.length() > 0) {
                List<CodeSetVersionBean> versionBeans = FastJsonUtil.JsonToData_CodeSetVersion(code);
                for (CodeSetVersionBean c : versionBeans) {//遍历典设版本
                    String codeset_version_id = c.getCodeset_version_id();
                    for (BitTypeTabItemBean b : beanList) {//遍历点位
                        getCodeSetList(codeset_version_id, b.getId());
                    }
                }
            }
        }
        for (BitTypeTabItemBean b : beanList) {//遍历点位
            getCodeSetList("", b.getId());
        }


    }

    public void getCodeSetList(String codeset_version_id, String pt_id) {
        MyApp.HTTP.getCodeSetList(AddChoiceModelHandler(), HttpStringUtil.SUCCESSED2, codeset_version_id, pt_id, null, 0, Integer.MAX_VALUE, MString.click_in);

    }

    private Handler AddChoiceModelHandler() {
        Handler choiceModelHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED2:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            ShardPreferencesTool.saveshare(MyApp.activity, MString.CodeSetList, (String) msg.obj);
                        }
                        break;

                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
        return choiceModelHandler;
    }


    /**
     * 获取踏勘点列表*
     */
    void getPointList(int code, String projectType, String stage_id, String explor_id, String... save) {
        MyApp.HTTP.getExplorationList(addPointHandler(stage_id), code, projectType, stage_id, explor_id, save);//获取踏勘点列表
    }

    /**
     * 获取踏勘点列表(台区)*
     */
    void getPointList(String stage_id, String explor_id, String... save) {
        MyApp.HTTP.getExplorationList(addPointHandler(stage_id), 3, "", stage_id, explor_id, save);
    }

    /**
     * 项目下载统计信息*
     */
    private void getPointSum(int code, String stage_id, String... save) {
        addPointSumHandler();
        MyApp.HTTP.getPointSum(pointSumHandler, code, stage_id,"", save);
    }

    /**
     * 项目项目基本信息*
     */
    private void getBaseData(int code, String stage_id, String... save) {
        AddBaseHandler();
        MyApp.HTTP.getProjectInfo(baseHandler, code, stage_id, save);
    }

    /**
     * 项目杆塔数据*
     */

    private void getPoleSum(int code, String stage_id, String voltageGrade, String... save) {
        addPoleSumHandler();
        MyApp.HTTP.getPoleSum(poleSumHandler, code, stage_id, voltageGrade, save);
    }

    /**
     * 项目用电户数*
     */
    private void getUserPoint(int code, String stage_id, String... save) {
        addUserPointHandler();
        MyApp.HTTP.getUserPoint(userPointHandler, code, stage_id, save);
    }

    /**
     * 项目下载台区数据*
     */

    private void getTransformerList(int code, String stage_id, String... save) {
        MyApp.HTTP.getTransformerList(addTransformerListHandler(stage_id), code, stage_id, save);
    }

    /**
     * 项目下台区统计数据*
     */
    private void getExplorSum(int code, String explor_id, String... save) {
        addExplorSumHandler();
        MyApp.HTTP.getExplorSum(explorSumHandler, code, explor_id, save);
    }

    /**
     * 项目台区跨越物数据*
     */
    private void getSectionCorss(int code, String explor_id, String... save) {
        addSectionCorssHandler();
        //MyApp.HTTP.getSectionCorss(sectionCorssHandler, code, explor_id, save);
    }

    /**
     * 项目台区材料数据*
     */
    private void getMaterialSum(int code, String explor_id, String... save) {
        addmaterialSumHandler();
        //MyApp.HTTP.getMaterialSum(materialSumHandler, code, explor_id, save);
    }

    /**
     * 遍历踏勘点具体数据监听*
     */

    void getExploration(int code, String exploration_id, String... save) {
        addexplorationHandler();
        MyApp.HTTP.getExploration(explorationHandler, code, exploration_id, save);
    }

    /**
     * 得到踏勘点下的照片数据*
     */
    public void getExpPhotoList(int code, String exploration_id, String... save) {
        addExpPhotoListHandler();
        MyApp.HTTP.getExpPhotoList(expPhotoList, code, exploration_id, save);
    }

    /**
     * 踏勘点跨越物上联节点数据*
     */
    private void getBeforeExp(int code, String exploration_id, String... save) {
        addBeforeExpHandler();
        MyApp.HTTP.getBeforeExp(beforeExpHandler, code, exploration_id, save);
    }

    /**
     * 踏勘点跨域物体上联数据的障碍物数据*
     */
    private void getChannelList(int code, String exploration_id, String... save) {
        addChannelListHandler();
        MyApp.HTTP.getChannelList(channelListHandler, code, exploration_id, save);
    }

    /**
     * 踏勘点跨域物关联的碍物列表*
     */
    private void getChannelAList(int code, String exploration_id, String... save) {
        addChannelAListHandler();
        MyApp.HTTP.getChannelAList(channelAListHandler, code, exploration_id, save);
    }

    /**
     * 踏勘点环境变量信息*
     */
    private void getEnvInfo(int code, String exploration_id, String... save) {
        addEnvInfoHandler();
        MyApp.HTTP.getEnvInfo(envInfoHandler, code, exploration_id, save);
    }

/*********************************************数据接收与处理**************************************************/
    /**
     * 遍历阶段列表_获取踏勘点*
     */
    void pullExploresListWithStageIdentifier(List<ProjectItemBean> data) {
        if (data == null || data.size() == 0) return;
        projectNum = 0;
        for (ProjectItemBean p : data) {
            if (MyApp.openIdent == null || MyApp.openIdent.length() == 0) return;

            getPointList(httpcode, "11", p.stage_id, "", p.stage_id, MString.ProjectStageExplorePointList + "_" + p.stage_id + "_11");//获取点位列表（新建）
            getPointList(HttpStringUtil.SUCCESSED3, "12", p.stage_id, "", p.stage_id, MString.ProjectStageExplorePointList + "_" + p.stage_id + "_12");//获取点位列表（拆旧）
            getPointSum(httpcode, p.stage_id, p.stage_id, MString.ProjectStageTotalInfo + "_" + p.stage_id);//下载统计信息 ProjectStageTotalInfo_StageId
            getBaseData(httpcode, p.stage_id, p.stage_id, MString.ProjectStageBaseInfo + "_" + p.stage_id); //项目基本信息 ProjectStageBaseInfo_StageId
            for (SystemTypeBean s : FastJsonUtil.JsonToData_Code(HttpStringCodeTableUtil.voltageGrade)) {
                getPoleSum(httpcode, p.stage_id, s.getTypecode(), p.stage_id, MString.ProjectStageTower + "_" + p.stage_id + "_" + s.getTypecode());//项目杆塔数据 ProjectStageTower_StageId_VoltageId
            }
            getUserPoint(httpcode, p.stage_id, p.stage_id, MString.ProjectStageElectric + "_" + p.stage_id);//项目用电户数 ProjectStageElectric_StageId
            getTransformerList(httpcode, p.stage_id, p.stage_id, MString.ProjectTransformerListFile + "_" + p.stage_id); //下载台区数据 ProjectTransformerListFile_StageId
            projectNum++;
        }
        projectsize = data.size();
    }

    /**
     * 遍历踏勘点列表_获取踏勘点信息*
     */
    void ProjectExplorePointBaseInfoDataFile(String stage_id, List<Exploration> list) {
        if (list == null || list.size() == 0) return;
        for (Exploration e : list) {
            if (MyApp.openIdent == null || MyApp.openIdent.length() == 0) return;
            getExploration(httpcode, e.exploration_id, stage_id, MString.ProjectExplorePointInfo + "_" + e.exploration_id);
            //遍历踏勘点具体数据 ProjectExplorePointInfo_ExploreId
            getExpPhotoList(httpcode, e.exploration_id, stage_id, MString.ProjectExplorePointInfoPhoto + "_" + e.exploration_id);
            //得到踏勘点下的照片数据 ProjectExplorePointInfoPhoto_ExploreId

            //踏勘点跨越物请求:
            getBeforeExp(httpcode, e.exploration_id, stage_id, MString.ProjectExploreAcrossBeforePoint + "_" + e.exploration_id);
            //踏勘点跨越物上联节点数据 ProjectExploreAcrossBeforePoint_ExploreId
            getChannelList(httpcode, e.exploration_id, stage_id, MString.ProjectExploreAcrossBeforePointChannelList + "_" + e.exploration_id);
            //踏勘点跨域物体上联数据的障碍物数据 ProjectExploreAcrossBeforePointChannelList_ExploreId
            getChannelAList(httpcode, e.exploration_id, stage_id, MString.ProjectExploreAcrossOnChannelList + "_" + e.exploration_id);
            //踏勘点跨域物关联的碍物列表 ProjectExploreAcrossOnChannelList_ExploreId
            getEnvInfo(httpcode, e.exploration_id, stage_id, MString.ProjectExploreEnvInfo + "_" + e.exploration_id);
            //踏勘点环境变量信息 ProjectExploreEnvInfo_ExploreId
        }
    }

    /**
     * 移动到SD卡*
     */
    private void SaveToSDCard() {
        if (projectsize == projectNum && TransformerNum == Transformersize) {
            //移动

        }
    }


    /**
     * 项目列表数据监听*
     */
    void addProjectListHandler() {
        if (projectListHandler == null) {
            projectListHandler = new Handler() {
                List<ProjectItemBean> data;

                @Override
                public void handleMessage(Message msg) {
                    switch (msg.what) {
                        case httpcode:
                            if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                                data = FastJsonUtil.JsonToGetProjectListBean((String) msg.obj);//拉取最新项目数据
                                List<ProjectItemBean> oldData = GetFileUtil.getProjectStageListFile();
                                if (oldData != null && data != null && data.size() > 0 && oldData.size() > 0) {
                                    try {

                                        List<ProjectItemBean> oData = new ArrayList<>();
                                        List<ProjectItemBean> NData = new ArrayList<>();
                                        oData.addAll(oldData);

                                        for (int i = 0; i < oldData.size(); i++) {
                                            for (int j = 0; j < data.size(); j++) {
                                                MyLog.L(MString.SUCCESSED + "---123data=" + JSON.toJSONString(data.get(j)));
                                                MyLog.L(MString.SUCCESSED + "---123oldData=" + JSON.toJSONString(oldData.get(i)));
                                                MyLog.L(MString.SUCCESSED + "---123oldData size=" + oldData.size());
                                                MyLog.L(MString.SUCCESSED + "---123oldData i=" + i);
                                                if (oldData.get(i) == null) {
                                                    oData.remove(oldData.get(i));

                                                }else  if (data.get(j) == null){

                                                }else{
                                                    if (data.get(j).getStage_id().equals(oldData.get(i).getStage_id()) || (oldData.get(i).getStage_id().equals(MString.code_null) || oldData.get(i).getStage_id().equals(MString.code_zero))) {
                                                        oData.remove(oldData.get(i));
                                                        if ((oldData.get(i).getStage_id().equals(MString.code_null) || oldData.get(i).getStage_id().equals(MString.code_zero))) {
                                                            NData.add(oldData.get(i));
                                                        } else {
                                                            NData.add(data.get(j));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        for (ProjectItemBean p : oData) {
                                            Delect(p);
                                        }
                                        oldData.clear();
                                        oldData.addAll(NData);

                                    } catch (Exception e) {

                                    }
                                }

                                SetFileUtil.setProjectStageListFile(DataFactory.GetSnyProject(data, oldData)); //存储

                                // projectListHandler.sendEmptyMessage(1);
                            } else {
                                //String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                                //ToastShow.showShort(context, s + ",缓存失败！");
                            }
                            CacheDialog.getInstence().getHandler().sendEmptyMessage(0);
                            break;
                        case 1:
                            pullExploresListWithStageIdentifier(data);
                            break;
                        case HttpStringUtil.ERROR:
                            // ToastShow.showShort(context, (String) msg.obj);
                            CacheDialog.getInstence().getHandler().sendEmptyMessage(1);
                            break;

                    }
                }
            };

        }
    }

    /**
     * 删除缓存中服务器已删除的项目
     **/
    private void Delect(ProjectItemBean bean) {
        String path = MyApp.File.getProPath(bean.getStage_id());//按id删除
        String path2 = MyApp.File.getProRequestPath(bean.getStage_id());
        MyApp.File.delete(new File(path));//删除缓存
        MyApp.File.delete(new File(path2));//删除同步缓存
        if (bean.getUUID() != null && bean.getUUID().length() > 0 && !bean.getUUID().equals(MString.code_zero)) {
            String path3 = MyApp.File.getProPath(bean.getUUID());//按uuid删除
            String path4 = MyApp.File.getProRequestPath(bean.getUUID());
            MyApp.File.delete(new File(path3));//删除缓存
            MyApp.File.delete(new File(path4));//删除同步缓存
        }
    }

    /**
     * 项目地图数据监听*
     */
    void addSearchAllProjectHandler() {
        searchAllProjectHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetSearchAllProject((String) msg.obj);
                            List<SearchProjectBean> data = FastJsonUtil.JsonToGetSearchAllProject((String) msg.obj);//拉取最新项目数据

//                          SetFileUtil.setMapProjectFile(DataFactory.GetProject(data, GetFileUtil.getMapProjectFile())); //存储
                            SetFileUtil.setMapProjectFile(data); //存储
                        } else {
                            //String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                            //ToastShow.showShort(context, s + ",缓存失败！");
                        }
                        CacheDialog.getInstence().getHandler().sendEmptyMessage(0);
                        break;

                    case HttpStringUtil.ERROR:
                        CacheDialog.getInstence().getHandler().sendEmptyMessage(1);
                        break;
                }
            }
        };
    }

    /**
     * 项目点位列表数据监听*
     */
    Handler addPointHandler(final String stage_id) {
        Handler pointHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            ProjectExplorePointBaseInfoDataFile(stage_id, FastJsonUtil.JsonToGetExplorationList((String) msg.obj));
                        }
                        break;

                    case HttpStringUtil.SUCCESSED3:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            ProjectExplorePointBaseInfoDataFile(stage_id, FastJsonUtil.JsonToGetExplorationList((String) msg.obj));
                        }
                        break;
                    case 3:
                        break;
                    case HttpStringUtil.ERROR:
                        //  ToastShow.showShort(context, (String) msg.obj);
                        break;

                }
            }
        };
        return pointHandler;
    }

    /**
     * 项目下载统计信息监听*
     */
    private void addPointSumHandler() {
        if (pointSumHandler == null) pointSumHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            // FastJsonUtil.JsonToGetPointSum((String) msg.obj);

                        }
                        break;
                    case HttpStringUtil.ERROR:
                        break;

                }
            }
        };
    }

    /**
     * 项目项目基本信息监听*
     */
    void AddBaseHandler() {
        if (baseHandler == null) baseHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                        }
                        break;
                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
    }

    /**
     * 项目杆塔数据监听*
     */
    void addPoleSumHandler() {
        if (poleSumHandler == null) poleSumHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                        }
                        break;

                    case HttpStringUtil.ERROR:

                        break;

                }
            }
        };
    }

    /**
     * 项目用电户数监听*
     */
    void addUserPointHandler() {
        if (userPointHandler == null) userPointHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetUserPoint((String) msg.obj);
                        }

                        break;

                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
    }

    /**
     * 项目下载台区数据监听*
     */
    Handler addTransformerListHandler(final String stage_id) {
        Handler transformerListHandler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            TransformerNum = 0;
                            List<Exploration> datas = FastJsonUtil.JsonToGetExplorationList((String) msg.obj);
                            for (Exploration e : datas) {
                                if (MyApp.openIdent == null || MyApp.openIdent.length() == 0)
                                    return;
                                getPointList(stage_id, e.exploration_id, stage_id, MString.ProjectTransformerExplorePointList + "_" + stage_id + "_" + e.exploration_id);
                                //台区下踏勘点列表
                                getExplorSum(httpcode, e.exploration_id, stage_id, MString.ProjectStageTransformerTotalInfo + "_" + stage_id + "_" + e.exploration_id);
                                //台区统计数据 ProjectStageTransformerTotalInfo_StageId_TransformerId
                                getSectionCorss(httpcode, e.exploration_id, stage_id, MString.ProjectStageAcross + "_" + stage_id + "_" + e.exploration_id);
                                //项目台区跨越物数据 ProjectStageAcross_StageId_TransformerId
                                getMaterialSum(httpcode, e.exploration_id, stage_id, MString.ProjectStageMaterial + "_" + stage_id + "_" + e.exploration_id);
                                //项目台区材料数据 ProjectStageMaterial_StageId_TransformerId

                                TransformerNum++;
                            }

                            Transformersize = datas.size();
                            SaveToSDCard();
                        }
                        break;

                    case HttpStringUtil.ERROR:
                        break;

                }
            }
        };
        return transformerListHandler;
    }

    /**
     * 项目下台区统计数据监听*
     */

    void addExplorSumHandler() {
        if (explorSumHandler == null) explorSumHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            // FastJsonUtil.JsonToGetPointSum((String) msg.obj);

                        } else {
                            // String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                            //ToastShow.showShort(context, s + ",获取项目统计失败！");
                        }
                        break;
                    case HttpStringUtil.ERROR:
                        break;

                }
            }
        };
    }

    /**
     * 项目台区跨越物数据监听*
     */
    private void addSectionCorssHandler() {
        if (sectionCorssHandler == null) sectionCorssHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetSectionCorss((String) msg.obj);

                        }
                        break;

                    case HttpStringUtil.ERROR:
                        break;

                }
            }
        };
    }

    /**
     * 项目台区材料数据监听*
     */
    private void addmaterialSumHandler() {
        if (materialSumHandler == null) materialSumHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetmaterialSum((String) msg.obj);
                        }
                        break;

                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
    }

    /**
     * 遍历踏勘点具体数据监听*
     */

    private void addexplorationHandler() {
        if (explorationHandler == null) explorationHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                        }
                        break;
                    case HttpStringUtil.ERROR:
                        break;

                }
            }
        };
    }

    /**
     * 得到踏勘点下的照片数据监听*
     */

    void addExpPhotoListHandler() {
        if (expPhotoList == null) expPhotoList = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToData_BackPhotos((String) msg.obj);
                        }

                        break;

                    case HttpStringUtil.ERROR:

                        break;
                }
            }
        };
    }

    /**
     * 踏勘点跨越物上联节点数据监听*
     */

    void addBeforeExpHandler() {
        if (beforeExpHandler == null) beforeExpHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetExploration_Id((String) msg.obj);
                        }
                        break;

                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
    }

    /**
     * 踏勘点跨域物体上联数据的障碍物数据监听*
     */
    private void addChannelListHandler() {
        if (channelListHandler == null) channelListHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            // FastJsonUtil.JsonToGetChannelList((String) msg.obj);
                        }
                        break;

                    case HttpStringUtil.ERROR:

                        break;
                }
            }
        };
    }

    /**
     * 踏勘点跨域物关联的碍物列表监听*
     */
    private void addChannelAListHandler() {
        if (channelAListHandler == null) channelAListHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetChannelAList((String) msg.obj);
                        }
                        break;

                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
    }

    /**
     * 踏勘点环境变量信息监听*
     */
    private void addEnvInfoHandler() {
        if (envInfoHandler == null) envInfoHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case httpcode:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            //FastJsonUtil.JsonToGetEnvInfo((String) msg.obj);
                        }
                        break;
                    case HttpStringUtil.ERROR:
                        break;
                }
            }
        };
    }

    /**
     * 人员缓存监听*
     */
    private Handler inItPersonnelHander(final String userType) {
        Handler personnelHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED2:
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            ShardPreferencesTool.saveshare(MyApp.activity, MString.UserByTypeList + userType, (String) msg.obj);
                        }
                        CacheDialog.getInstence().getHandler().sendEmptyMessage(0);
                        break;

                    case HttpStringUtil.ERROR:
                        CacheDialog.getInstence().getHandler().sendEmptyMessage(1);
                        break;

                }
            }
        };
        return personnelHandler;
    }
}
